package com.spring.oa.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.util.JSONPObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.spring.oa.web.service.OaUserService;
import com.spring.security.core.util.ApplicationUtils;

/**
 * Oa用户相关
 * @author wojunyu
 *
 */
@Controller
@RequestMapping(value = "/oaUser")
public class OaUserController {
	
    @Resource
    private OaUserService oaUserService;
	
	@RequestMapping(value = "/login")
    @ResponseBody
    public Object login(String token,String username,String password,HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = oaUserService.login(token, username, password);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
	
	@RequestMapping(value = "/queryOaUser")
    @ResponseBody
    public Object queryOaUser(String token,String username,String dept_id,String include,HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = oaUserService.queryOaUser(token, username, dept_id,include);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
}
